﻿using System;

namespace GenericSubClass
{
    class Program
    {
        static void Main(string[] args)
        {
            SubStack<int,int> baseStack = new SubStack<int,int>();
            baseStack.Push(200);
            Console.WriteLine(baseStack.Pop());

            
            SubStack<object, string> subStack = new SubStack<object, string>();
            subStack.Push("Hello");
            Console.WriteLine(subStack.Pop());

            //反过来
            //SubStack<string, object> subStack2 = new SubStack<string, object>();
        }
    }

    class BaseStack<T>
    {
        protected T[] StatckValues = new T[100];
        protected int position = 0;
        public T GetT(int position)
        {
            return StatckValues[position];
        }

        public virtual void Push(T value)
        {
            StatckValues[position++] = value;

        }
        public virtual T Pop()
        {

            return StatckValues[--position];

        }
    }

    class SubStack<T,T2> : BaseStack<T> where T2:T
    {
        private T2 newT2Value = default(T2);

        public override void Push(T value)
        {
            newT2Value = (T2)value;
        }
        public override T Pop()
        {
           return  newT2Value;
        }

    }
}
